package com.sky.controller.User;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.UserService;
import com.sky.service.UserShoppingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "购物车相关接口")
public class UserShoppingCart {
    @Autowired
    private UserShoppingService userShoppingService;

    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     */
     @PostMapping("/add")
     @ApiOperation("添加购物车")
     public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
         log.info("添加餐品:{}", shoppingCartDTO);

         userShoppingService.add(shoppingCartDTO);

         return Result.success();
     }

    /**
     * 添加购物车
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> showCart(){
      List<ShoppingCart> list=userShoppingService.showcart();
         return Result.success(list);
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result deleteCart(){
        userShoppingService.deleteCart();
         return Result.success();
    }

    /**
     * 删除一个商品
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    @ApiOperation("删除一个商品")
    public Result subCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        userShoppingService.subCart(shoppingCartDTO);
        return Result.success();
    }
}
